<template>
  <!-- 
    <nav>
    <router-link to="/">Home</router-link> |
    <router-link to="/about">About</router-link>
  </nav> 
  -->
  <router-view></router-view>
  <div class="online-service-fixed">
    <div class="sitewidget">
      <ul class="online-service-list">
        <!-- 
          <li>
          <div>
            <a class="onlineService_e" href="mailto:service@apricus.com">
              <i class="fa fa-envelope" aria-hidden="true"></i>
              <span>E-MAIL</span>
            </a>
          </div>
        </li> 
        -->
        <template v-for="(item, index) in followList" :key="index">
          <li>
            <div>
              <a class="" :href="item.url" target="_blank">
                <i :class="item.icon" aria-hidden="true"></i>
                <span>{{ item.name }}</span>
              </a>
            </div>
          </li>
        </template>
      </ul>
    </div>
  </div>
</template>

<script>
import {
  reactive,
  toRefs,
  onBeforeMount,
  onMounted,
  getCurrentInstance,
} from "vue";
import { useStore } from "vuex";
export default {
  name: "App",
  components: {},
  props: {},
  setup() {
    const { proxy } = getCurrentInstance();
    const data = reactive({
      followList: [
        {
          url: "https://www.facebook.com/liang.nick.33",
          name: "Facebook",
          icon: "fa fa-facebook-square",
          color: "#1877f2",
        },
        {
          url: "https://www.linkedin.com",
          name: "Linkedin",
          icon: "fa fa-linkedin-square",
          color: "#007bb5",
        },
        {
          url: "https://www.instagram.com",
          name: "Instagram",
          icon: "fa fa-instagram",
          color: "#1da1f2",
        },
      ],
    });
    const refData = toRefs(data);
    const store = useStore();
    onBeforeMount(() => {
      //在页面加载时读取sessionStorage里的状态信息,否则获取初始化数据
      if (sessionStorage.getItem("store")) {
        proxy.$store.replaceState(
          Object.assign(
            {},
            proxy.$store.state,
            JSON.parse(sessionStorage.getItem("store"))
          )
        );
      } else {
        proxy.$store.dispatch("initData");
      }

      //在页面刷新时将vuex里的信息保存到sessionStorage里
      window.addEventListener("beforeunload", () => {
        // sessionStorage.setItem("store", JSON.stringify(proxy.$store.state));
      });
    });
    onMounted(() => {
      document.dispatchEvent(new Event("render-event"));
    });
    return {
      ...refData,
    };
  },
};
</script>

<style lang="scss">
// #app {
//   font-family: Avenir, Helvetica, Arial, sans-serif;
//   -webkit-font-smoothing: antialiased;
//   -moz-osx-font-smoothing: grayscale;
//   text-align: center;
//   color: #2c3e50;
// }

// nav {
//   padding: 30px;

//   a {
//     font-weight: bold;
//     color: #2c3e50;

//     &.router-link-exact-active {
//       color: #42b983;
//     }
//   }
// }
.online-service-fixed {
  position: fixed;
  z-index: 99;
  right: 0;
  top: 30%;

  .sitewidget {
    font-size: 14px;
    color: #797979;
    font-weight: 400;
    letter-spacing: 0;
    line-height: 1.8em;
    text-align: left;
  }

  a {
    color: #fff;
    text-decoration: none;
  }

  ul.online-service-list {
    border-radius: 0;
    padding: 0;
    list-style: none;

    background-color: #2c323e;

    li {
      div {
        position: absolute;
        right: 0;
        top: 0;
        height: 0;
        width: 0;

        display: flex;
        justify-content: center;
        align-items: center;
        height: 54px;
        width: 54px;
        padding: 0 15px;
        transition: width 0.3s ease-in;
        margin: 0 0 0 auto;
      }

      div:hover {
        width: auto;
        background-color: #f6c00d;
      }

      div:hover span {
        display: inline;
      }
    }

    li {
      height: 54px;
      width: 54px;
      border-bottom: 1px solid rgba(255, 255, 255, 0.2);
      position: relative;
      white-space: nowrap;

      a {
        color: #fff;
        font-size: 26px;
        overflow: hidden;
        text-decoration: none;
      }

      i {
        position: relative;
        top: 2px;
        font-size: 26px;
      }

      span {
        line-height: 28px;
        font-size: 18px;
        margin: 0 10px 0 14px;
      }
    }
  }
}
</style>
